using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;
using System.IO;
using System.Diagnostics;

namespace BoOnce.Core.Helpers
{
    public class XmlStorage
    {

        public static void Save(String filepath, Object obj)
        {
            XmlSerializer serializer = new XmlSerializer(obj.GetType());
            TextWriter txtWriter = new StreamWriter(filepath);
            serializer.Serialize(txtWriter, obj);
            txtWriter.Close();
            txtWriter.Dispose();
        }

        public static void Save(String filepath, Type type, Object obj)
        {
            XmlSerializer serializer = new XmlSerializer(type);
            TextWriter txtWriter = new StreamWriter(filepath);
            serializer.Serialize(txtWriter, obj);
            txtWriter.Close();
            txtWriter.Dispose();
        }

        public static Object Load(String filepath, System.Type type)
        {
            XmlSerializer serializer = new XmlSerializer(type);
            TextReader txtReader = new StreamReader(filepath);
            Object obj = serializer.Deserialize(txtReader);
            txtReader.Close();
            txtReader.Dispose();
            return obj;
        }
    }
}
